Dart.PowerTCP.SslSockets Namespace > Tcp Class > Receive Method : Receive(Byte[],Int32,Int32,SocketFlags) Method |
Receive data from the host, specifying a buffer, offset, count and SocketFlags value.
[Visual Basic]
<DescriptionAttribute("Receive data into your buffer.")>
Overloads Public Function Receive( _
ByVal buffer() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer, _
ByVal socketFlags As SocketFlags _
) As Segment
[C#]
[DescriptionAttribute("Receive data into your buffer.")]
public Segment Receive(
byte[] buffer,
int offset,
int count,
SocketFlags socketFlags
);
[C++]
[DescriptionAttribute("Receive data into your buffer.")]
public: Segment* Receive(
byte[]* buffer,
int offset,
int count,
SocketFlags socketFlags
)
[C++/CLI]
[DescriptionAttribute("Receive data into your buffer.")]
public:
Segment^ Receive(
bytearray<buffer>^ buffer,
int offset,
int count,
SocketFlags socketFlags
)
A Segment object encapsulating the data received.
Exception | Description |
---|---|
IOException | The stream is not Readable. |
ArgumentNullException | buffer is null. |
ArgumentOutOfRangeException | offset or count is less than 0. |
ArgumentException | offset + count is greater than the length of buffer. |
SocketException | The socket is not connected. |
After connecting, data can be received using the Tcp.Recieve method. All Receive methods return a Segment object, encapsulating the data received. In order to access the data, simply access the properties of the Segment object returned such as Buffer (to access the data in a byte array) or ToString (to access the data as a string).
This method is the only way to receive data from a host while specifying a SocketFlags parameter.
The following example demonstrates sending bytes to the server with a SocketFlag option.
[Visual Basic]
Private Sub Test()
' Connect to an echo port
Tcp1.Connect("atropos", 7)
Dim sendbuffer() As Byte = System.Text.Encoding.Default.GetBytes("abcdefg")
' Send some bytes with "OutOfBand" SocketFlag option
Tcp1.Send(sendbuffer, 0, sendbuffer.Length, SocketFlags.OutOfBand)
Dim recvbuffer(sendbuffer.Length) As Byte
' Server will echo the bytes back. Receive the bytes.
Tcp1.Receive(recvbuffer, 0, recvbuffer.Length, SocketFlags.None)
' Close the connection.
Tcp1.Close()
End Sub
[C#]
private void Test()
{
// Connect to the echo port
tcp1.Connect("atropos", 7);
byte[] sendbuffer = System.Text.Encoding.Default.GetBytes("abcdefg");
// Send some bytes with "OutOfBand" SocketFlag option
tcp1.Send(sendbuffer, 0, sendbuffer.Length, SocketFlags.OutOfBand);
byte[] recvbuffer = new byte[sendbuffer.Length];
// Server will echo the bytes back. Receive the bytes.
tcp1.Receive(recvbuffer, 0, recvbuffer.Length, SocketFlags.None);
// Close the connection.
tcp1.Close();
}
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Tcp Class | Tcp Members | Overload List
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.